package com.qk.controller;

import com.qk.anno.Log;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.server.ActivityServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    ActivityServer activityServer;
    //查询列表
    @GetMapping
    public Result findActivityByList(Integer channel,Integer type,Integer status,
    @RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pageSize){
        PageResult result = activityServer.findActivityByList(channel,type,status,page,pageSize);
        return Result.success(result);
    }
    //删除数据
    @Log
    @DeleteMapping("/{id}")
    public Result delActivityById(@PathVariable Integer id) {
        activityServer.delActivityById(id);
        return Result.success();
    }
    //添加
    @Log
    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityServer.addActivity(activity);
        return Result.success();
    }
    //根据Id查询
    @GetMapping("/{id}")
    public Result findActivityById(@PathVariable Integer id){
        Activity activity = activityServer.findActivityById(id);
        return Result.success(activity);
    }
    //修改
    @Log
    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityServer.updateActivity(activity);
        return Result.success();
    }
    //查询指定类型参数
    @GetMapping("/type/{type}")
    public Result findActivityByType(@PathVariable Integer type){
        return Result.success(activityServer.findActivityByType(type));
    }
}
